import lejos.nxt.Button;
import lejos.nxt.ButtonListener;
import lejos.nxt.LCD;


public class InterfaceController implements ButtonListener{

	private static int store;
	private static int step;
	private static int min;
	
	public InterfaceController(){
		Button.RIGHT.addButtonListener(this);
		Button.LEFT.addButtonListener(this);
	}
	
	// Implicitly assume that start is also the minimal value of the data
	public int promptForInteger(String prompt, int start, int step) {
		return promptForInteger(prompt, start, step, start);
	}

	public int promptForInteger(String prompt, int start, int step, int min) {
		LCD.drawString(prompt, 0, 0);
		LCD.drawInt(start, 1, 1);
		
		InterfaceController.min = min;
		InterfaceController.store = start;
		InterfaceController.step = step;

		Button.ENTER.waitForPressAndRelease();

		return InterfaceController.store;
	}
	
	public void buttonReleased(Button b) {
		if (b.equals(Button.LEFT) && !(InterfaceController.store - InterfaceController.step < InterfaceController.min)) {
			InterfaceController.store -= InterfaceController.step;
		} else if (b.equals(Button.RIGHT)) {
			InterfaceController.store += InterfaceController.step;
		}
		
		LCD.drawString("             ", 1, 1);
		LCD.drawInt(InterfaceController.store, 1, 1);
	}
	
	public void buttonPressed(Button b) {

	}
}
